//
//  YKTopicVoiceView.m
//  baisi
//
//  Created by 吴高烽 on 16/10/16.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKTopicVoiceView.h"
#import "YKTopic.h"
#import "YKShowPictureViewController.h"
#import <UIImageView+WebCache.h>
@interface YKTopicVoiceView ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *voiceLenghtLabel;
@property (weak, nonatomic) IBOutlet UILabel *playCountLable;

@end

@implementation YKTopicVoiceView
+(instancetype)voiceView{
    return  [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil]lastObject];
}
-(void)awakeFromNib{
    [super awakeFromNib];
    self.autoresizingMask = UIViewAutoresizingNone ;
    self.imageView.userInteractionEnabled = YES ;
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showPictureView)]];
}
-(void)setTopic:(YKTopic *)topic{
    _topic = topic ;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.large_image]];
    self.voiceLenghtLabel.text = [NSString stringWithFormat:@"%zd播放",topic.playcount];
    NSInteger min = topic.voicetime/60 ;
    NSInteger sec = topic.voicetime%60 ;
    self.playCountLable.text = [NSString stringWithFormat:@"%02zd:%02zd",min,sec];

}
-(void)showPictureView{
    YKShowPictureViewController *showPVC = [[YKShowPictureViewController alloc]init];
    showPVC.topic = self.topic ;
    [YKKeyWindow.rootViewController presentViewController:showPVC animated:YES completion:nil];
}
@end
